# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=linux-headers
pkgver=5.7.8
_kernver=${pkgver%.*}
pkgrel=0
pkgdesc="Linux system headers"
url="http://kernel.org"
arch="all"
license="GPL-2.0-only"
makedepends="perl rsync"
options="!check !dbg !strip !tracedeps"
source="https://kernel.org/pub/linux/kernel/v5.x/linux-$_kernver.tar.xz
	https://kernel.org/pub/linux/kernel/v5.x/patch-$pkgver.xz
	revert-broken-uapi.patch
	0003-remove-inclusion-of-sysinfo.h-in-kernel.h.patch
	include-uapi-linux-swab-Fix-potentially-missing-__always_inline.patch
	"
builddir="$srcdir/linux-$_kernver"

prepare() {
	if [ "$_kernver" != "$pkgver" ]; then
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1
	fi
	default_prepare
}

package() {
	local _carch=$CARCH

	case "$_carch" in
	aarch64*) _carch="arm64" ;;
	arm*) _carch="arm" ;;
	mips*) _carch="mips" ;;
	s390*) _carch="s390" ;;
	ppc*) _carch="powerpc" ;;
# not sure about this --	ppc64*) _carch="powerpc64" ;;
	esac

	mkdir -p "$pkgdir/usr"
	make headers_install ARCH="$_carch" INSTALL_HDR_PATH="$pkgdir/usr"

	find "$pkgdir/usr" \( -name .install -o -name ..install.cmd \) -exec \
		rm -f {} \;

	# provided by libdrm
	rm -rf "$pkgdir"/usr/include/drm
}

sha512sums="45bde01593f6147c8c169b9e46b4b56eee998142552ae0ff82f1dd21b1fd54f3b32f6283f6bd77ea717d374672167849e468c157f235d2f12f7d7816e4623bf6  linux-5.7.tar.xz
4820a45fba9fa299181a96598a96bbdbf6f5faaf1862173d9cca3cc5ea84c21d8e7d4baf0601697565fad3b7d3c76085f4ac86a726961b62c356d70968edc48f  patch-5.7.8.xz
32597f2672d1ec365a936d15041a7cf219ef9353241d4a5c378244cf2fc155610443a19bbcd391c86099a0b08486c45e042ec7c90b0d04fe675c3ad0ffc36b53  revert-broken-uapi.patch
302283b1b5f560c850e24aad73febcf7f906ed62b4cad2d826bf140ffe59191631f3cd4ac29525c349cdfe61aba6a47886a0d76f1c6a4a16b744d59b94ea5df8  0003-remove-inclusion-of-sysinfo.h-in-kernel.h.patch
7cfa786144009c52d682e307bb512156e4812d7abe03b3fed99651a02d80567d47ee6f347f88d083c1b9805e0c09625fc3df08a8d0ae96b169d24eb5b83917b7  include-uapi-linux-swab-Fix-potentially-missing-__always_inline.patch"
